import { prop, modelOptions } from '@typegoose/typegoose' 
import { ApiProperty } from '@nestjs/swagger' 
import { hashSync } from 'bcryptjs'

@modelOptions({
    schemaOptions: {
        timestamps: true
    }
})
export class User {
    @prop()
    @ApiProperty({ description: '用户名', example: 'admin'})
    username: string

    @prop({
        select: false,
        get(val) {
            return val
        },
        set(val) {
            return val ? hashSync(val) : val
        }
    })
    @ApiProperty({ description: '密码', example: 'admin'})
    password: string

}